Skip to content

Remove BackwardsTokenizer based parenthesized_range references in ruff_linter#21836

Merged
MichaReiser merged 7 commits intoastral-sh:mainfrom
denyszhak:feat/ruff-linter-to-use-optimized-parenthesized-range
Dec 11, 2025
Merged

Remove BackwardsTokenizer based parenthesized_range references in ruff_linter#21836
MichaReiser merged 7 commits intoastral-sh:mainfrom
denyszhak:feat/ruff-linter-to-use-optimized-parenthesized-range

Conversation

@denyszhak
Copy link
Contributor

Summary

ruff_linter now uses optimized version of parenthesized_range on already precomputed tokens instead of generating those over again

Closes #21835

Test Plan

Ensured old tests are still successful. If any additional check required please hint the way and I would love to test.

@astral-sh-bot
Copy link

astral-sh-bot bot commented Dec 8, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@denyszhak denyszhak force-pushed the feat/ruff-linter-to-use-optimized-parenthesized-range branch from 6f5bce9 to e00dd64 Compare December 8, 2025 01:10
@AlexWaygood AlexWaygood added the performance Potential performance improvement label Dec 8, 2025
@AlexWaygood AlexWaygood removed their request for review December 8, 2025 07:38
@MichaReiser MichaReiser added internal An internal refactor or improvement and removed performance Potential performance improvement labels Dec 8, 2025
@MichaReiser MichaReiser changed the title fix: ruff_linter uses optimized paranthesized_range Remove BackwardsTokenizer based paranthesized_range implementation Dec 8, 2025
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this allow us to remove the old parenthesized_ranges implementation or are there usages outside ruff_linter?

@AlexWaygood AlexWaygood changed the title Remove BackwardsTokenizer based paranthesized_range implementation Remove BackwardsTokenizer based parenthesized_range implementation Dec 8, 2025
@denyszhak
Copy link
Contributor Author

Does this allow us to remove the old parenthesized_ranges implementation or are there usages outside ruff_linter?

Only 1 place left: needs_line_break under ruff_python_formatter still uses the old implementation. It looks like it's possible to migrate this one as well. Would you like me to do that and remove old implementation or focus purely on ruff_linter?

@MichaReiser
Copy link
Member

Only 1 place left: needs_line_break under ruff_python_formatter still uses the old implementation. It looks like it's possible to migrate this one as well. Would you like me to do that and remove old implementation or focus purely on ruff_linter?

Let's focus on the linter for now.

@MichaReiser MichaReiser changed the title Remove BackwardsTokenizer based parenthesized_range implementation Remove BackwardsTokenizer based parenthesized_range references in ruff_linter Dec 9, 2025
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. We mainly need to look into the regression

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thank you.

I'll wait for #21895 to land first as this can otherwise lead to panics

denyszhak and others added 2 commits December 11, 2025 11:45
@MichaReiser MichaReiser merged commit 27912d4 into astral-sh:main Dec 11, 2025
38 checks passed
dcreager added a commit that referenced this pull request Dec 11, 2025
* origin/main: (29 commits)
  Document range suppressions, reorganize suppression docs (#21884)
  Ignore ruff:isort like ruff:noqa in new suppressions (#21922)
  [ty] Handle `Definition`s in `SemanticModel::scope` (#21919)
  [ty] Attach salsa db when running ide tests for easier debugging (#21917)
  [ty] Don't show hover for expressions with no inferred type (#21924)
  [ty] avoid unions of generic aliases of the same class in fixpoint (#21909)
  [ty] Squash false positive logs for failing to find `builtins` as a real module
  [ty] Uniformly use "not supported" in diagnostics (#21916)
  [ty] Reduce size of ty-ide snapshots (#21915)
  [ty] Adjust scope completions to use all reachable symbols
  [ty] Rename `all_members_of_scope` to `all_end_of_scope_members`
  [ty] Remove `all_` prefix from some routines on UseDefMap
  Enable `--document-private-items` for `ruff_python_formatter` (#21903)
  Remove `BackwardsTokenizer` based `parenthesized_range` references in `ruff_linter` (#21836)
  [ty] Revert "Do not infer types for invalid binary expressions in annotations" (#21914)
  Skip over trivia tokens after re-lexing (#21895)
  [ty] Avoid inferring types for invalid binary expressions in string annotations (#21911)
  [ty] Improve overload call resolution tracing (#21913)
  [ty] fix missing heap_size on Salsa query (#21912)
  [ty] Support implicit type of `cls` in signatures (#21771)
  ...
dcreager added a commit that referenced this pull request Dec 11, 2025
* origin/main: (36 commits)
  [ty] Defer all parameter and return type annotations (#21906)
  [ty] Fix workspace symbols to return members too (#21926)
  Document range suppressions, reorganize suppression docs (#21884)
  Ignore ruff:isort like ruff:noqa in new suppressions (#21922)
  [ty] Handle `Definition`s in `SemanticModel::scope` (#21919)
  [ty] Attach salsa db when running ide tests for easier debugging (#21917)
  [ty] Don't show hover for expressions with no inferred type (#21924)
  [ty] avoid unions of generic aliases of the same class in fixpoint (#21909)
  [ty] Squash false positive logs for failing to find `builtins` as a real module
  [ty] Uniformly use "not supported" in diagnostics (#21916)
  [ty] Reduce size of ty-ide snapshots (#21915)
  [ty] Adjust scope completions to use all reachable symbols
  [ty] Rename `all_members_of_scope` to `all_end_of_scope_members`
  [ty] Remove `all_` prefix from some routines on UseDefMap
  Enable `--document-private-items` for `ruff_python_formatter` (#21903)
  Remove `BackwardsTokenizer` based `parenthesized_range` references in `ruff_linter` (#21836)
  [ty] Revert "Do not infer types for invalid binary expressions in annotations" (#21914)
  Skip over trivia tokens after re-lexing (#21895)
  [ty] Avoid inferring types for invalid binary expressions in string annotations (#21911)
  [ty] Improve overload call resolution tracing (#21913)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update ruff_linter to use optimized version of parenthesized_ranges

3 participants